<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/all.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <script src="../plugins/healthbackend.js"></script>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>预约列表</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="手机号/姓名" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                <el-button @click="_findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="address" label=" 预约地址" align="center"></el-table-column>
                <el-table-column label="预约确认" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.affirm == '0' ? '未确定' : scope.row.affirm == '1' ? '已确定' : '已取消' }}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="member.name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="member.phoneNumber" label="手机号" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                <el-table-column prop="setmeal.sname" label="预约套餐" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleSure(scope.row)">确认预约</el-button><br>
                        <el-button style="margin-top: 3px" type="warning" size="mini" @click="handleCancel(scope.row)">取消预约</el-button><br>
                        <el-button style="margin-top: 3px" size="mini" type="danger" @click="handleDelete(scope.row)">删除预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!--新增预约-->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="身份证号" prop="idCard">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="出生日期">
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        value-format="yyyy-MM-dd"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="年龄">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="预约时间">
                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        value-format="yyyy-MM-dd"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="婚姻">
                                                <el-select v-model="formData.marriage">
                                                    <el-option label="已婚" value="1"></el-option>
                                                    <el-option label="未婚" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="预约地址">
                                                <el-select v-model="formData.address" placeholder="请选择"style="width: 80%;margin: auto;height: 40px">
                                                    <el-option
                                                            v-for="map in mapList"
                                                            :key="map.name"
                                                            :label="map.name"
                                                            :value="map.name">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐名称</th>
                                            <th>适用人群</th>
                                            <th>套餐介绍</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="setmealId" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.sname}}</label></td>
                                            <td><label :for="c.id">{{c.sex == '0' ? '不限' : c.sex == '1' ? '男' : '女'}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            activeName:'first',
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:10,//每页显示的记录数
                total:0,//总记录数
                queryString:null//查询条件
            },
            mapList:[],
            addressList:[],
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            tableData:[],//新增和编辑表单中对应的套餐列表数据
            setmealId:[]//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交

        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //添加
            handleAdd () {
                var idCard = this.formData.idCard;
                var phoneNumber=this.formData.phoneNumber;
                if(!checkIdCard(idCard)){
                    //身份证号输入不合法
                    this.$message.error("身份证号码输入错误，请重新输入");
                    return false;
                }
                if (! checkTelephone(phoneNumber)){
                    this.$message.error("手机号码输入错误，请重新输入");
                    return false;
                }
                //判断套餐是否合适
                for(var x=0;x<this.tableData.length;x++){
                    if(this.setmealId[0]==this.tableData[x].id){
                        if(this.tableData[x].sex != "0"){
                            if(this.formData.sex != this.tableData[x].sex){
                                this.$message.error("性别不适合!请选择其他套餐")
                                return false;
                            }
                        }
                    }
                }

                axios.post("/orderlist/add.do?setmealId="+this.setmealId,this.formData).then((res)=>{
                            if (res.data.flag){
                                this.$message({
                                    message:res.data.message,
                                    type:"success"
                                });
                                this.dialogFormVisible=false;
                                this.findPage();
                            } else{
                                this.$message.error(res.data.message);
                            }
                        }).finally(()=>{
                            this.findPage();
                        })


            },
            //分页查询
            findPage() {
                //发送ajax请求
                var prom ={
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                }
                axios.post("/orderlist/findPage.do",prom).then((res)=>{
                    //解析Controller 响应回的数据，为模型对象赋值
                    this.pagination.total=res.data.total;
                    this.dataList=res.data.rows;
                });
            },
            _findPage(){
                this.pagination.currentPage=1;
                this.findPage();
            },
            // 重置表单
            resetForm() {
                this.formData = {};//重置表单
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible=true;
                this.activeName = 'first';//默认选中first对应的tab
                this.setmealId = [];
                //发送ajax请求，查询所有套餐的数据，显示到页面上
                axios.get("/orderlist/findAll.do").then((res)=>{
                    if (res.data.flag){
                        this.tableData=res.data.data;
                    } else {
                        this.$message.error(res.data.message)
                    }
                });
                axios.get("/orderlist/findAllAddress.do").then((res)=>{
                    if (res.data.flag){
                        this.mapList=res.data.data;
                    } else {
                        this.$message.error(res.data.message)
                    }
                });

            },
            // 确认预约
            handleSure(row) {
                axios.get("/orderlist/orderSure.do?id="+row.id).then((res)=>{
                    if (res.data.flag){
                        this.$message({
                            message:res.data.message,
                            type:"success"
                        });
                        this.findPage();
                    } else{
                        //失败
                        this.$message.error(res.data.message);
                    }
                });
            },
            handleCancel(row){
                axios.get("/orderlist/orderCancel.do?id="+row.id).then((res)=>{
                    if (res.data.flag){
                        this.$message({
                            message:res.data.message,
                            type:"success"
                        });
                        this.findPage();
                    } else{
                        //失败
                        this.$message.error(res.data.message);
                    }
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //设置最新的页码
                this.pagination.currentPage=currentPage;
                //重新调用findPage方法
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                this.$confirm("确认删除预约吗","提示",{type:'warning'})
                    .then(()=>{
                        axios.get("/orderlist/delete.do?id="+row.id).then((res)=>{
                            if (!res.data.flag){
                                //删除失败
                                this.$message.error(res.data.message);
                            }else {
                                //删除成功
                                this.$message({
                                    type:"success",
                                    message:res.data.message
                                });
                                this.findPage();
                            }
                        });
                    });
            }
        }
    })
</script>
</html>